home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / scroll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  5.3 KB  |  183 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. #ifndef NO_MEMORY_H
  23. #include <memory.h>
  24. #endif
  25.  
  26. /* undefine any macros for functions defined in this module */
  27. #undef    scroll
  28. #undef    scrl
  29. #undef    wscrl
  30.  
  31. /* undefine any macros for functions called by this module if in debug mode */
  32. #ifdef PDCDEBUG
  33. #endif
  34.  
  35. #ifdef PDCDEBUG
  36. char *rcsid_scroll  = "$Id$";
  37. #endif
  38.  
  39. /*man-start*********************************************************************
  40.  
  41.   Name:                                                        scroll
  42.  
  43.   Synopsis:
  44.       int scroll(WINDOW *win);
  45.       int scrl(int n);
  46.       int wscrl(WINDOW *win, int n);
  47.  
  48.   X/Open Description:
  49.      scroll() causes the window to scroll up one line.  This involves 
  50.      moving the lines in the window data strcture.
  51.  
  52.      With the scrl() and wscrl() routines, for positive n scroll the 
  53.      window up n lines (line i+n becomes i); otherwise scroll the 
  54.      window down n lines.
  55.  
  56.      For these functions to work, scrolling must be enabled via 
  57.      scrollok().
  58.  
  59.      Note that scrl() and scroll() may be macros.
  60.  
  61.      Note also that scrolling is not allowed if the supplied window 
  62.      is a PAD.
  63.  
  64.   X/Open Return Value:
  65.      All functions return OK on success and ERR on error.
  66.  
  67.   X/Open Errors:
  68.      No errors are defined for this function.
  69.  
  70.   NOTE:
  71.      The behaviour of Unix curses is to clear the line with a space
  72.      and attributes of A_NORMAL. PDCurses clears the line with the
  73.      window's current attributes (including current colour). To get
  74.      the behaviour of PDCurses, #define PDCURSES_WCLR in curses.h or
  75.      add -DPDCURSES_WCLR to the compile switches.
  76.  
  77.   Portability                             X/Open    BSD    SYS V
  78.                                           Dec '88
  79.       scroll                                Y        Y       Y
  80.       scrl                                  -        -      4.0
  81.       wscrl                                 -        -      4.0
  82.  
  83. **man-end**********************************************************************/
  84.  
  85. /***********************************************************************/
  86. int    scroll(WINDOW *win)
  87. /***********************************************************************/
  88. {
  89. #ifdef PDCDEBUG
  90.     if (trace_on) PDC_debug("scroll() - called\n");
  91. #endif
  92.  
  93.     if (win == (WINDOW *)NULL)
  94.         return( ERR );
  95.  
  96.     return(wscrl(win,1));
  97. }
  98. /***********************************************************************/
  99. int    wscrl(WINDOW *win, int n)
  100. /***********************************************************************/
  101. {
  102.     register int    i;
  103.     register int    l;
  104.     chtype*    ptr;
  105.     chtype*    temp;
  106. static    chtype    blank;
  107.  
  108.     if (win == (WINDOW *)NULL)
  109.         return( ERR );
  110.  
  111. #if defined(PDCURSES_WCLR)
  112.     blank    = win->_blank | win->_attrs;
  113. #else
  114. /* wrs (4/10/93) account for window background */
  115.     blank = win->_bkgd;
  116. #endif
  117.  
  118.     /*
  119.      * Check if window scrolls or window is a PAD
  120.      */
  121.     if (!win->_scroll || (win->_flags & _PAD))
  122.     {
  123.         return( ERR );
  124.     }
  125.  
  126. /* wrs -- 7/11/93 -- quick add to original scroll() routine to implement
  127.  *                   scrolling for a specified number of lines
  128.  *                    (not very efficient for more than 1 line)
  129.  */
  130.  
  131.     if ( n >= 0 )
  132.         {
  133.         for ( l=0; l<n; l++ ) 
  134.             {
  135.             temp = win->_y[win->_tmarg];
  136.             for (i = win->_tmarg; (i < win->_bmarg); i++)
  137.                 {
  138.                 win->_y[i] = win->_y[i + 1];    /* re-arrange line
  139.                                      * pointers */
  140.                 win->_firstch[i] = 0;
  141.                 win->_lastch[i] = win->_maxx - 1;
  142.             }
  143.             for (ptr = temp; (ptr - temp < win->_maxx); ptr++)
  144.                 *ptr = blank;                /* make a blank line */
  145.             win->_y[win->_bmarg] = temp;
  146.             win->_firstch[win->_bmarg] = 0;
  147.             win->_lastch[win->_bmarg] = win->_maxx - 1;
  148.             }
  149.         }
  150.     else 
  151.         {
  152.         for ( l=n; l<0; l++ ) 
  153.             {
  154.             temp = win->_y[win->_bmarg];
  155.             for (i = win->_bmarg; (i > win->_tmarg); i--)
  156.                 {
  157.                 win->_y[i] = win->_y[i - 1];    /* re-arrange line
  158.                                      * pointers */
  159.                 win->_firstch[i] = 0;
  160.                 win->_lastch[i] = win->_maxx - 1;
  161.                 }
  162.             for (ptr = temp; (ptr - temp < win->_maxx); ptr++)
  163.                 *ptr = blank;                /* make a blank line */
  164.             win->_y[win->_tmarg] = temp;
  165.             win->_firstch[win->_tmarg] = 0;
  166.             win->_lastch[win->_tmarg] = win->_maxx - 1;
  167.             }
  168.         }
  169.     return( OK );
  170. }
  171. /***********************************************************************/
  172. int    scrl(int n)
  173. /***********************************************************************/
  174. {
  175. #ifdef PDCDEBUG
  176.     if (trace_on) PDC_debug("scrl() - called\n");
  177. #endif
  178.  
  179.  
  180.     return(wscrl(stdscr,n));
  181. }
  182.